<template>
  <view class="index_class">
    <view class="setup">
      <view class="per-lists" style="margin-top: 0;">
        <view class="items title" >
          <view>头像</view>
          <upLoader ref="upLoader" :width="120" :height="120"></upLoader>
        </view>
      </view>
      
      <view class="per-lists">
        <!-- @click="getnav('/pagesB/personalSon/ModifynickName')" -->
        <view class="items">
          用户名
          <view style="width:80%">
            <input type="text" v-model="userinfo.user_name" placeholder="请输入用户名" />
          </view>
        </view>
      </view>
      <view class="per-lists">
        <!-- @click="getnav('/pagesB/personalSon/ModifynickName')" -->
        <view class="items" @click="showDisalePhone">
          手机号
          <view style="width:80%">
            <input type="text" v-model="userinfo.phone" disabled />
          </view>
        </view>
      </view>
      
      
      <view class="person-button">
        <button type="warn" @click="confirmEdit" class="btn">确认修改</button>
      </view>
    </view>
  </view>
</template>

<script>
import upLoader from '@/components/upLoader'

export default {
  onShow() {
    if (uni.getStorageSync("userInfo")) {
      this.userinfo = JSON.parse(uni.getStorageSync("userInfo"));
      if (this.userinfo.birth) {
        this.date = this.$formatDateTime(this.userinfo.birth * 1000).split(
            " "
        )[0];
      }
      this.index = Number(this.userinfo.sex)
          ? Number(this.userinfo.sex) - 1
          : 0;
    }
  },
components:{
  upLoader
},
  data() {
    return {
      userinfo: {},
      isShow: false,
      upLoadAction:'',
      formData:{}
    };
  },
  methods: {

    confirmEdit() {
      const uploadedCoverImg = this.$refs.upLoader.resultSrc
      this.$loading();
      const data = {
        headimgurl:uploadedCoverImg,
        user_name: this.userinfo.user_name
      };
      this.$http.editprofile(data).then(res=>{
        if (res.status == 200) {
          this.$toast(res.mess);
          this.$hideLoading()
          uni.$emit('accountLogin',{})
          setTimeout(() => {
            this.$u.route({type: 'back'})
          }, 1000);
        }
      })
    
      
    },
    showDisalePhone(){
      this.$u.toast('手机号暂不可修改')
    }
    
  },
  onUnload(){
    uni.$off('accountLogin',()=>{})
  }
};
</script>

<style scoped>
.per-lists .items {
  flex: 1;
  justify-content: flex-end;
}
.per-lists .items input {
  flex: 1;
}
</style>
